www.gusucode.com > 24Beta 虚拟主机版 1.0.0 Beta源码程序 > 24Beta 虚拟主机版 1.0.0 Beta源码程序/24Beta-1.0.0-vhost/protected/controllers/MController.php

    <?php

class MController extends CController
{
    public function init()
    {
        $accepts = $_SERVER['HTTP_ACCEPT'];
        if (strpos($accepts, 'text/html') !== false) {
            $this->layout = '3g';
        } else {
            header('Content-type: text/vnd.wap.wml; charset=' . app()->charset);
            $this->layout = 'wap';
        }
    }
    
    
	public function actionIndex()
	{
	    $posts = Post::model()->getRssPosts(param('wapPostNums'));
		$this->render($this->layout . '_index', array(
		    'posts' => $posts,
		));
	}
	
	public function actionShow()
	{
	    $pid = (int)$_GET['aid'];
	    $post = Post::model()->with('topic')->findByPk($pid);
	    if (!$post) {
	        throw new CHttpException(404, '此文章不存在');
	    }
	    
	    $post->visit_nums += param('visitNumsStep');
	    $post->update();
	    $this->render($this->layout . '_show', array(
	        'post' => $post,
	    ));
	}
	
	public function actionComment()
	{
	    $pid = (int)$_GET['aid'];
	    
	    $post = Post::model()->with('topic')->findByPk($pid);
	    if (!$post) {
	        throw new CHttpException(404, '此文章不存在');
	    }
	    
	    $criteria = new CDbCriteria();
		// 评论显示的条数
        $criteria->order = 'id asc';
        $criteria->condition = 'post_id = :postId and isshow = ' . Comment::YES;
        $criteria->params = array('postId' => $pid);
        $comments = Comment::model()->findAll($criteria);
        $this->render($this->layout . '_comment', array(
            'post' => $post,
            'comments' => $comments,
        ));
	}
}